package com.czmh.etc.onlinepubsys.enums.cmg;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 招商局ETC新系统平台-api状态码枚举对象
 */
@ApiModel("招商局ETC新系统平台-api状态码枚举对象")
public enum ApiCodeEnum {
	SUCCESS("SUCCESS", "业务处理成功"),
	CONNECTION_REST("521", "服务器连接失败"),
	SOCKET_TIME_OUT ("522", "服务器连接超时"),
	FAIL("FAIL", "业务处理超时"),
	NOT_FOUND("NOT_FOUND", "未找到相匹配的数据"),
	ERR_NUMBER_FORMAT("ERR_NUMBER_FORMAT", "错误的数字格式"),
	ERR_JSON_FORMAT("ERR_JSON_FORMAT", "错误的JSON格式"),
	ERR_DATE_OR_TIME_FORMAT("ERR_DATE_OR_TIME_FORMAT", "错误的日期或时间格式"),
	ERR_PARAMETER_ALL_EMPTY("ERR_PARAMETER_ALL_EMPTY", "所以参数为空"),
	ERR_PARAMETER_IS_EMPTY("ERR_PARAMETER_IS_EMPTY", "部分参数为空"),
	ERR_OVERFLOW_RANGE("ERR_OVERFLOW_RANGE", "取值越出范围"),
	ERR_SIG_FAILED("ERR_SIG_FAILED", "签名失败"),
	ERR_CHECK_SIG_FAILED("ERR_CHECK_SIG_FAILED", "验签失败"),
	ERR_ENCRYPTION_FAILED("ERR_ENCRYPTION_FAILED",  "加密失败"),
	ERR_DECRYPT_FAILED("ERR_DECRYPT_FAILED",  "解密失败"),
	ERR_NOT_ONLY_ONE("ERR_NOT_ONLY_ONE",  "查询返回不只一条数据"),
	ERR_DB("ERR_DB",  "数据库操作失败"),
	ERR_STRING_LEN("ERR_STRING_LEN",  "字符长度错误"),
	ERR_UNKOWN("ERR_UNKOWN",  "未知错误"),
	ERR_TOKEN_INVALID("ERR_TOKEN_INVALID",  "token失效"),
	ERR_AUTHENTICATION_FAILED("ERR_AUTHENTICATION_FAILED",  "授权失败"),
	ERR_USER_IS_EMPTY("ERR_USER_IS_EMPTY",  "登录用户为空"),
	ERR_PASSWORD_IS_EMPTY("ERR_PASSWORD_IS_EMPTY",  "登录密码为空"),
	ERR_USER_NOT_EXIST("ERR_USER_NOT_EXIST",  "登录用户不存在"),
	USER_EXIST("1004",  "登录用户存在"),
	ERR_LOGIN_PASSWORD("ERR_LOGIN_PASSWORD",  "登录密码错误"),
	ERR_USER_DISABLED("ERR_USER_DISABLED",  "登录用户禁用"),
	ERR_USER_REGISTER_FAILED("ERR_USER_REGISTER_FAILED",  "用户注册失败"),
	ERR_MODIFY_PASSWORD_FAILED("ERR_MODIFY_PASSWORD_FAILED",  "密码修改失败"),
	ERR_TYPES_NOT_MATCH("ERR_TYPES_NOT_MATCH",  "types类型不匹配"),
	ERR_USER_EXIST("ERR_USER_EXIST",  "登录用户已存在"),
	ERR_MOBILE_NUMBER_NOT_MATCH("ERR_MOBILE_NUMBER_NOT_MATCH",  "手机号格式错误"),
	ERR_SMS_VERIFY_FAILED("ERR_SMS_VERIFY_FAILED",  "短信验证码验证失败"),
	ERR_SMS_CODE_INVALID("ERR_SMS_CODE_INVALID",  "短信验证码失效"),
	ERR_SMS_SEND_FAILED("ERR_SMS_SEND_FAILED",  "验证码发送失败"),
	ERR_CARDNO_IS_EMPTY("ERR_CARDNO_IS_EMPTY",  "卡号为空"),
	ERR_CARDSTATE_UNNORMAL("ERR_CARDSTATE_UNNORMAL",  "卡状态不正常"),
	ERR_CARD_NONSUPPORT_BINDING("ERR_CARD_NONSUPPORT_BINDING",  "卡不支持绑定"),
	ERR_INVOKE_SERVICE_FAILED("ERR_INVOKE_SERVICE_FAILED",  "调用第三方服务失败"),
	ERR_EMAIL_NOT_MATCH("ERR_EMAIL_NOT_MATCH",  "邮箱格式错误"),
	ERR_OTHER("ERR_OTHER",  "其他错误");

	/** 编码 */
	@ApiModelProperty("编码")
	private String code;
	/** 描述 */
	@ApiModelProperty("描述")
	private String desc;

	private ApiCodeEnum(String code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public static Map<String, Map<String, Object>> toMap() {
		ApiCodeEnum[] ary = ApiCodeEnum.values();
		Map<String, Map<String, Object>> enumMap = new HashMap<String, Map<String, Object>>();
		for (int num = 0; num < ary.length; num++) {
			Map<String, Object> map = new HashMap<String, Object>();
			String key = ary[num].name();
			map.put("desc", ary[num].getDesc());
			enumMap.put(key, map);
		}
		return enumMap;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List toList() {
		ApiCodeEnum[] ary = ApiCodeEnum.values();
		List list = new ArrayList();
		for (int i = 0; i < ary.length; i++) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("desc", ary[i].getDesc());
			map.put("name", ary[i].name());
			list.add(map);
		}
		return list;
	}

	public static ApiCodeEnum getEnum(String name) {
		ApiCodeEnum[] arry = ApiCodeEnum.values();
		for (int i = 0; i < arry.length; i++) {
			if (arry[i].name().equalsIgnoreCase(name)) {
				return arry[i];
			}
		}
		return null;
	}

	/**
	 * 取枚举的json字符串
	 * 
	 * @return
	 */
	public static String getJsonStr() {
		ApiCodeEnum[] enums = ApiCodeEnum.values();
		StringBuffer jsonStr = new StringBuffer("[");
		for (ApiCodeEnum senum : enums) {
			if (!"[".equals(jsonStr.toString())) {
				jsonStr.append(",");
			}
			jsonStr.append("{id:'").append(senum).append("',desc:'").append(senum.getDesc()).append("'}");
		}
		jsonStr.append("]");
		return jsonStr.toString();
	}

}